package com.jweb.framework.core.util;

import java.io.IOException;
import java.io.Writer;


public class FilterWriterA extends FilterWriterB {

	private final boolean d;
    final char a;
    final String b;
    
    public FilterWriterA(Writer writer, String s, char c, boolean flag)
    {
        super(writer);
        d = flag;
        a = c;
        b = a(c);
    }

    public void write(int i)
        throws IOException
    {
        if(i <= 60)
        {
            if(i == a)
            {
                out.write(b);
                return;
            }
            if(i == 60)
            {
                out.write("&lt;");
                return;
            }
            if(i == 38)
            {
                out.write("&amp;");
                return;
            }
            if(i == 13 && d)
            {
                out.write("&#13;");
                return;
            }
            if(i < 32)
                if(i == 0)
                {
                    a();
                } else
                {
                    a(i);
                    return;
                }
        }
        out.write(i);
    }

    public void write(char ac[], int i, int j)
        throws IOException
    {
        j += i;
        char c = a;
        do
        {
            int k = i;
            int l = 0;
            String s = null;
            for(; i < j; i++)
            {
                l = ac[i];
                if(l > 60)
                    continue;
                if(l == c)
                {
                    s = b;
                    break;
                }
                if(l == 60)
                {
                    s = "&lt;";
                    break;
                }
                if(l == 38)
                {
                    s = "&amp;";
                    break;
                }
                if(l == 13 && d)
                {
                    s = "&#13;";
                    break;
                }
                if(l >= 32)
                    continue;
                if(l == 0)
                    a();
                break;
            }

            int i1 = i - k;
            if(i1 > 0)
                out.write(ac, k, i1);
            if(s != null)
            {
                out.write(s);
                s = null;
            } else
            if(i < j)
                a(l);
        } while(++i < j);
    }

    public void write(String s, int i, int j)
        throws IOException
    {
        j += i;
        char c = a;
        do
        {
            int k = i;
            int l = 0;
            String s1 = null;
            for(; i < j; i++)
            {
                l = s.charAt(i);
                if(l > 60)
                    continue;
                if(l == c)
                {
                    s1 = b;
                    break;
                }
                if(l == 60)
                {
                    s1 = "&lt;";
                    break;
                }
                if(l == 38)
                {
                    s1 = "&amp;";
                    break;
                }
                if(l == 13 && d)
                {
                    s1 = "&#13;";
                    break;
                }
                if(l >= 32)
                    continue;
                if(l == 0)
                    a();
                break;
            }

            int i1 = i - k;
            if(i1 > 0)
                out.write(s, k, i1);
            if(s1 != null)
            {
                out.write(s1);
                s1 = null;
            } else
            if(i < j)
                a(l);
        } while(++i < j);
    }
	
}
